/****** Object:  Stored Procedure dbo.CGO_GameEnrollmentGetPlayedCount    Script Date: Sunday, March 06, 2011 ******/
IF EXISTS ( SELECT  *
            FROM    dbo.sysobjects
            WHERE   id = OBJECT_ID(N'dbo.CGO_GameEnrollmentGetPlayedCount')
                    AND OBJECTPROPERTY(id, N'IsProcedure') = 1 ) 
  DROP PROCEDURE dbo.CGO_GameEnrollmentGetPlayedCount
GO


/* -------------------------------------------------------------------------------------
/   GameEnrollmentGetList 
/  ------------------------------------------------------------------------------------- */
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE dbo.CGO_GameEnrollmentGetPlayedCount
  @PortalID INT ,
  @EventID INT ,
  @GameID INT ,
  @UserID INT,
  @EnrollStatusID INT
AS 
  IF @EventID IS NULL 
    BEGIN
      SET @EventID = 0
    END
  IF @GameID IS NULL 
    BEGIN
      SET @GameID = 0
    END
  IF @UserID IS NULL 
    BEGIN
      SET @UserID = 0
    END
    
  SELECT  COUNT(*)
  FROM    dbo.CGO_GameEnrollment
  WHERE   PortalID = @PortalID
          AND ( @EventID = 0
                OR EventID = @EventID
              )
          AND ( @GameID = 0
                OR GameID = @GameID
              )
          AND ( @UserID = 0
                OR UserID = @UserID
              )
          AND ( @EnrollStatusID = 0 
                OR EnrollStatusID = @EnrollStatusID
              )
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO